<template>
<el-upload
  ref="my-upload"
  class="upload-demo"
  action=""
  name="file"
  :http-request="handleUpload"
  multiple
  :accept="accept_str"
  :show-file-list="show_file_list"
  :limit="1"
  >
  <el-button type="primary" :loading="button_loading" plain>{{button_name}}</el-button>
</el-upload>
</template>
<script>
  import { uploadFile } from '@/api/upload.js';
  export default {
    name:"ExcelImport",
    props:['post_url','show_file_list','accept_str','handle_result'],   //post_url:上传目标url
    data() {
      return {
          button_loading:false,
          button_name:'批量导入'
      };
    },
    methods: {
      handleUpload(file){
          this.button_loading=true;
          this.button_name='正在导入';
          let that=this;
          let fd=new FormData();
          fd.append('file',file.file);
          uploadFile(fd,this.post_url).then(function(response){
              that.button_loading=false;
              that.button_name='批量导入';
              that.handle_result(response.data);
              //清空限制，可以重新导入
              that.$refs['my-upload'].clearFiles();
          })
      },

    }
  }
</script>
